<?php
//关注
function dr_guanzhu_list($uid, $myuid) {

    if (!$uid || !$myuid) {
        return '<div class=" d-beijing-hui d-yuanjiao-20 d-neikuang-5-10 d-div-you d-wenzi-12">关 注</div>';
    }
	$row = \Phpcmf\Service::M()->table('member_friend')->where('uid', (int)$myuid)->where('touid', (int)$uid)->getRow();
	if ($row) {
	    // return $row['isdouble'] ? 2 : 1;
		return '<div class=" d-beijing-hui d-yuanjiao-20 d-neikuang-5-10 d-div-you d-wenzi-12"><i class="fa fa-check-circle-o"></i> 已关注</div>';
	}else{
		return '<div class=" d-beijing-hui d-yuanjiao-20 d-neikuang-5-10 d-div-you d-wenzi-12">关 注</div>';
	}
	
	return '<div class=" d-beijing-hui d-yuanjiao-20 d-neikuang-5-10 d-div-you d-wenzi-12">关 注</div>';

    /*if ($id && $uid){
		$rt = \Phpcmf\Service::M()->db->table(SITE_ID.'_'.MOD_DIR.'_form_son_favorite')->where('uid', $uid)->where('cid', $id)->countAllResults();
		//SITE_ID.'_'.MOD_DIR.'_form_son'
		//$rt = $this->db->table($tablename.'1_quanzi_cart')->where('cid', $id)->where('uid', $id)->countAllResults();
	  //$rt = \Phpcmf\Service::M()->db->table(SITE_ID.'_tag_favorite')->where('uid', $uid)->where('cid', $id)->countAllResults();
	    if ($rt){
	    	return '<div class=" d-gao-40 d-kuan-40 d-yuanjiao-50 d-beijing-hei-f0 d-kuan-juzhong"><img src="static/quan/img/shoucang5.png" width="30" class="d-shang-4 d-kuan-juzhong"/></div><div class="d-shang-4 d-wenzi-12">已藏</div>';
	    }else{
			return '<div class=" d-gao-40 d-kuan-40 d-yuanjiao-50 d-beijing-hei-f0 d-kuan-juzhong"><img src="static/quan/img/shoucang4.png" width="30" class="d-shang-4 d-kuan-juzhong"/></div><div class="d-shang-4 d-wenzi-12">收藏</div>';
		}
    } 
	return '<div class=" d-gao-40 d-kuan-40 d-yuanjiao-50 d-beijing-hei-f0 d-kuan-juzhong"><img src="static/quan/img/shoucang4.png" width="30" class="d-shang-4 d-kuan-juzhong"/></div><div class="d-shang-4 d-wenzi-12">收藏</div>';
    */
}
function dr_hy_is_friend($uid, $myuid) {

    if (!$uid || !$myuid) {
        return 0;
    }

    $row = \Phpcmf\Service::M()->table('member_friend')->where('uid', (int)$myuid)->where('touid', (int)$uid)->getRow();
    if ($row) {
        return $row['isdouble'] ? 2 : 1;
    }

    return 0;
}

// 插件地址url
function dr_hy_url($uid) {

    $config = \Phpcmf\Service::M('app')->get_config('huiyuan');
    if ($config['home']['urlrule']) {
        $data = dr_member_info($uid);
        if (!$data) {
            return 'uid(#'.$uid.')不存在';
        }
        return dr_web_prefix('/').str_replace(['{username}', '{id}', '{uid}'], [$data['username'], $data['uid'], $data['uid']], ltrim($config['home']['urlrule'], '/'));
    }

    return dr_web_prefix('index.php?s=huiyuan&c=show&uid='.$uid);
}

// 搜索url
function dr_hx_search_url($params = [], $name = '', $value = '') {
    if ($name) {
        if (is_array($name)) {
            foreach ($name as $i => $_name) {
                if (isset($value[$i]) && dr_strlen($value[$i])) {
                    $params[$_name] = $value[$i];
                } else {
                    unset($params[$_name]);
                }
            }
        } else {
            if (dr_strlen($value)) {
                $params[$name] = $value;
            } else {
                unset($params[$name]);
            }
        }
    }

    if (is_array($params)) {
        foreach ($params as $i => $t) {
            if (dr_strlen($t) == 0) {
                unset($params[$i]);
            }
        }
    }

    $config = \Phpcmf\Service::M('app')->get_config('huiyuan');
    $rule = !$params && !$name ? $config['search']['urlrule'] : $config['search']['urlrule_page'];
    if ($rule) {
        $data['param'] = dr_search_rewrite_encode($params, null);
        if ($params && !$data['param']) {
            log_message('error', '空间无法通过[搜索参数字符串规则]获得参数');
        }
        $rep = new \php5replace($data);
        $url = preg_replace_callback("#{([a-z_0-9]+)}#Ui", array($rep, 'php55_replace_data'), $rule);
        $url = preg_replace_callback('#{([a-z_0-9]+)\((.*)\)}#Ui', array($rep, 'php55_replace_function'), $url);
        return dr_web_prefix(str_replace('//', '/', '/' . $url));
    } else {
        return dr_web_prefix('index.php?s=huiyuan&' . trim( @http_build_query($params), '&'));
    }
}